<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/context/mytags.jsp"%>
<div class="table-scrollable">
	<table class="table table-striped table-hover table-success">
		<thead>
			<tr>
				<th>#</th>
				<th>联系人</th>
				<th>电话</th>
				<th>取件地址</th>
				<th>商品名称</th>
				<th>取件日期</th>
				<th>操作</th>
			</tr>
		</thead>
		<tbody>
			<c:forEach items="${noticebillList }" var="item" varStatus="vs">
			<tr>
				<td>${vs.count}</td>
				<td>${item.delegater}</td>
				<td>${item.telephone}</td>
				<td>${item.pickaddress }</td>
				<td>${item.product}</td>
				<td>${item.formatterPickdate}</td>
				<td>
					<a href="javascript:;" class="btn btn-sm blue" onclick="open_diaodu_modal('${item.id}')">
						<i class="fa fa-edit"></i>人工调度
					</a>
				</td>
			</tr>
			</c:forEach>
		</tbody>
	</table>
</div>

<div class="modal fade" tabindex="-1" role="dialog" id="diaodu_modal">
  <div class="modal-dialog" role="document">
     <div class="fileinput-preview thumbnail"  style="width: 350px; height: 130px;">
	  	<div class="form-group">
		    <label class="col-md-4 control-label">通知单编号:</label>
		    <div class="col-md-8">
		      <input type="text" name="id" class="form-control" readonly="readonly">
		    </div>
		  </div>
		  
	  	 <div class="form-group">
		    <label class="col-md-4 control-label">选择取派员:</label>
		    <div class="col-md-8">
		      <select class="form-control select2" id="staffSelect" name="staffId">
	          </select>
		    </div>
		  </div>
		  
		  <div align="center">
			 <button type="button" class="btn btn-primary" onclick="diaodu()">
	           <spring:message code="btn.save"></spring:message>
	         </button>
          </div>
	  </div>
  </div>
</div>

<script type="text/javascript">
	
	function open_diaodu_modal(id) {
		
		$("input[name='id']").val(id);
		var staffListUrl = "${webRoot}/staff/listAjax";
		$.post(staffListUrl,{},function(result){
			
			if(result.data.length > 0) {
				$("#staffSelect").empty();
				$.each(result.data, function(index,item){
					$("#staffSelect").append("<option value='"+ item.id +"'>"+ item.name +"</option>");
				})
			}
		})
		
		$("#diaodu_modal").modal(function(){
			backdrop:"static"
		});
	}
	
	function diaodu() {
		
		var url = "${webRoot}/noticebill/diaodu";
		
		var noticebillId = $("input[name='id']").val();
		var staffId = $("#staffSelect").val();
		var data = {"id":noticebillId, "staffId":staffId};
		
		$.post(url, data, function(result){
			if(result.code == 0) {
				layer.msg(result.message, {shift: 1});
				setTimeout(function(){
					$("#diaodu_modal").modal('hide');
				}, 1200);
				
			}else {
				layer.msg(result.message, {shift: 6});
			}
		})
		
		$("#diaodu_modal").on('hidden.bs.modal',function(){
			search();
		})
	}
		
</script>
